package serova.valeriya.electricity;


import org.apache.commons.lang.StringUtils;
import java.text.ParseException;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import java.io.Writer;

import java.text.NumberFormat;
import java.util.List;



public class ReportUtils {
	public static void doReport(String content, Input input, double payment, Writer out){		
	Velocity.init();	
	VelocityContext vc = new VelocityContext();	
	vc.put("previousRegistration", input.getPreviousRegistration());		
	vc.put("currentRegistration", input.getCurrentRegistration());
	vc.put("electricity", input.calculateElectricity());
	vc.put("payment", payment);	
	NumberFormat nf = NumberFormat.getInstance();
	nf.setMinimumFractionDigits(2);
	nf.setMaximumFractionDigits(2);
	vc.put("number", nf);	
	
	Velocity.evaluate(vc, out, StringUtils.EMPTY, content);		
}
	
	
	public static void doStatistic(String content, String dateFirst, String dateLast,  int p, List <String> stat,  Writer out)throws ParseException{		
		Velocity.init();	
		VelocityContext vc = new VelocityContext();	
		vc.put("dateFirst", Result.getDateFirst());
		vc.put("dateLast", Result.getDateLast());
		vc.put("p", Result.getPreviousRegistrationForStat());			
		vc.put("billStatistic", Result.getStatisticDataObjects(stat));	
		
		Velocity.evaluate(vc, out, StringUtils.EMPTY, content);		
	}
}
	



